#include "hplcqinfineautosamplerprotocol.h"
#include "hplcqinfineautosamplersendpacket.h"
#include "hplcqinfineautosamplerparsepacket.h"
#include "hplcqinfineautosamplerprotocoldata.h"
#include "hplcqinfineautosamplerparsesystempacket.h"
#include "hplcqinfineautosamplersendsystempacket.h"
#include "common/hplcqinfinemakepacket.h"
#include "common/hplcqinfinefindpacket.h"

namespace hplc
{
namespace qinfine
{

HplcQinfineAutoSamplerProtocol::HplcQinfineAutoSamplerProtocol(AutoSamplerParam &param, QObject *parent)
    : HplcQinfineAutoSamplerProtocol (*new HplcQinfineAutoSamplerProtocolData(), param, parent)
{

}

HplcQinfineAutoSamplerProtocol::HplcQinfineAutoSamplerProtocol(HplcQinfineAutoSamplerProtocolData &data, AutoSamplerParam &param, QObject *parent)
    : HplcQinfineProtocolCommon (data, param, parent)
    , m_param(&param)
{
    HplcQinfineAutoSamplerParsePacket *parser = new HplcQinfineAutoSamplerParsePacket(data, param, this);
    HplcQinfineAutoSamplerSendPacket *sender = new HplcQinfineAutoSamplerSendPacket (data, this);
    connect(sender, &HplcQinfineSendCommonPacket::requestSend, this, &HplcQinfineProtocolCommon::requestSend);

    HplcQinfineAutoSamplerParseSystemPacket *systemParser = new HplcQinfineAutoSamplerParseSystemPacket(data, param, this);
    HplcQinfineAutoSamplerSendSystemPacket *systemSender = new HplcQinfineAutoSamplerSendSystemPacket(data);

    data.m_parser = parser;
    data.m_sender = sender;
    data.m_systemParser = systemParser;
    data.m_systemSender = systemSender;
}

HplcQinfineAutoSamplerProtocol::~HplcQinfineAutoSamplerProtocol()
{
    HplcQinfineAutoSamplerProtocolData *d = static_cast<HplcQinfineAutoSamplerProtocolData*>(m_d);
    delete d->m_sender;
    delete d->m_parser;
    delete d->m_systemParser;
    delete d->m_systemSender;
}

HplcQinfineAutoSamplerSendPacket *HplcQinfineAutoSamplerProtocol::getAutoSamplerSender()
{
    return static_cast<HplcQinfineAutoSamplerSendPacket*>(m_d->m_sender);
}

HplcQinfineAutoSamplerSendSystemPacket *HplcQinfineAutoSamplerProtocol::getAutoSamplerSystemSender()
{
    HplcQinfineAutoSamplerProtocolData *m_d = static_cast<HplcQinfineAutoSamplerProtocolData*>(this->m_d);
    return m_d->m_systemSender;
}

void HplcQinfineAutoSamplerProtocol::setModel(quint8 model)
{
//    m_param->
}

} // qinfine
} // hplc
